﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace SC.GridManage.API.Write.Myfilters
{
    public class GMExceptionFilter : IExceptionFilter
    {
        private readonly ILogger<GMExceptionFilter> logger;

        public GMExceptionFilter(ILogger<GMExceptionFilter> logger)
        {
            this.logger = logger;
        }
        /// <summary>
        /// 当有异常发生时,在方法里处理异常
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnException(ExceptionContext context)
        {
            logger.LogError("捕捉到全局异常:"+context.Exception.Message);
            context.ExceptionHandled = true;}
    }
}
